home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 2008-06-19 | 38.5 KB | 1,108 lines
var CC = Components.classes; var CI = Components.interfaces; /** * Class manages all the icons on status bar */ function statusBarIcon(id, labelId) { this._icon = null; this._iconLabel = null; this._init(id, labelId); } statusBarIcon.prototype = { _init: function (id, labelId) { try { this._icon = document.getElementById(id); if(labelId) this._iconLabel = document.getElementById(labelId); } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::statusBarIcon::_init()=>Exception: "+e,YB_LOG_MESSAGE); } }, setImage: function (url) { this._icon.setAttribute("src",url) }, showIcon: function () { this._icon.hidden = false; this._icon.collapsed = false; }, hideIcon: function () { this._icon.hidden = true; this._icon.collapsed = true; }, setLabel: function (val) { this._iconLabel.value = val; }, showLabel: function () { this._iconLabel.style.display = ""; }, hideLabel: function () { this._iconLabel.style.display = "none"; } } /** * Class manages all the popup windows on status bar */ function popWindow(id) { this.id = id; this.posX = null; this.posY = null; this.textnode = null; this.isOpen = false; this.popWind = document.getElementById(this.id); this.enabled = true; } popWindow.prototype = { prepareContent: function (id, content) { try { this.textnode = document.createTextNode(content); document.getElementById(id).replaceChild(this.textnode, document.getElementById(id).firstChild); } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::popWindow::prepareContent()=>Exception: "+e,YB_LOG_MESSAGE); } }, perpareElement: function (id, attrName, attrValue) { try { document.getElementById(id).setAttribute(attrName, attrValue); document.getElementById(id).setAttribute(attrName, attrValue); } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::popWindow::prepareElement()=>Exception: "+e,YB_LOG_MESSAGE); } }, /** * Prepare pupup position based on parameter passed broad positioning * Calculate screen resolution and window screen position and show popup accordingly */ preparePosition: function(broaderPosition){ var maxWidth = screen.width - parseInt(this.popWind.firstChild.style.minWidth); var maxHeight = screen.height - parseInt(this.popWind.firstChild.style.minHeight); var winX = window.screenX; var winY = window.screenY; var winWidth = window.innerWidth; var winHeight = window.innerHeight; var posWidth = winX + winWidth - parseInt(this.popWind.firstChild.style.minWidth); var posHeight = winY + winHeight - parseInt(this.popWind.firstChild.style.minHeight); if(!broaderPosition) broaderPosition = 'bottomright'; switch(broaderPosition){ case 'bottomright': //calculate position to put popup at bottom right part of window if(maxWidth <= posWidth) this.posX = maxWidth; else if(maxWidth > posWidth) this.posX = posWidth; if(maxHeight <= posHeight) this.posY = maxHeight; else if(maxHeight > posHeight) this.posY = posHeight; this.posX -= 10; this.posY -= 10; yDebug.print("ybookmarkStatusOverlay.js::popWindow::preparePosition()=>: maxWidth-"+maxWidth+" posWidth-"+posWidth+" X-"+this.posX+" Y-"+this.posY,YB_LOG_MESSAGE); if(this.posX >= 0 && this.posY >= 0) return true; else return false; } }, show: function (objRef) { if(!this.enabled) return; /** * Do nothing if its already open */ if(this.isOpen) { this.hide(); this.isOpen = false; } try { /** * Show popup window */ //this.popWind.position = "end_after"; //this.popWind.position = "before_end"; //this.popWind.showPopup(objRef,this.posX,this.posY,'popup','bottomright','topright'); //if(!objRef.boxObject || objRef.boxObject.screenX < 0 || objRef.boxObject.screenY < 0) { //not visible //alert("alert icon is not visible"); //return; //} //alert(objRef.boxObject.screenX + ":" + objRef.boxObject.screenY); //this.popWind.showPopup(objRef,objRef.boxObject.screenX,objRef.boxObject.screenY,'popup','bottomright','topright'); if(this.posX && this.posY) { this.popWind.showPopup(objRef,this.posX,this.posY,'popup','bottomright','topright'); } else { this.popWind.showPopup(objRef,-1,-1,'popup','bottomright','topright'); } this.isOpen = true; } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::popWindow::show()=>Exception: "+e,YB_LOG_MESSAGE); } }, hide: function () { if(!this.popWind) return; try { this.popWind.hidePopup(); this.isOpen = false; } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::popWindow::hide()=>Exception: "+e,YB_LOG_MESSAGE); } }, enable: function () { this.enabled = true; }, disable: function () { this.enabled = false; } } //Changes tag icon color for bookmarked urls function changeTagIcon(url) { if(!url) { return; } var storeService = Components.classes["@mozilla.org/ybookmarks-store-service;1"]. getService(Components.interfaces.nsIYBookmarksStoreService); var bookmarkResource = storeService.isBookmarked( url ); yDebug.print ( "Existing entry for " + url ); var toolbarTagIcon = document.getElementById("del-button-tagPage"); var styleClassName = "toolbar-tag-effect"; var navbar = document.getElementById("nav-bar"); if(navbar && (navbar.getAttribute("iconsize") == "small")) { styleClassName = "toolbar-tag-effect-small"; } if(toolbarTagIcon && bookmarkResource) { toolbarTagIcon.setAttribute("class", styleClassName); toolbarTagIcon.setAttribute("del", "true"); } else { toolbarTagIcon.setAttribute("class", styleClassName); toolbarTagIcon.setAttribute("del", "false"); } } /** * Listner class for adress bar changes to provide data for tagometer */ var urlBarListener = { QueryInterface: function(aIID) { if (aIID.equals(Components.interfaces.nsIWebProgressListener) || aIID.equals(Components.interfaces.nsISupportsWeakReference) || aIID.equals(Components.interfaces.nsISupports)) return this; throw Components.results.NS_NOINTERFACE; }, onLocationChange: function(aProgress, aRequest, aURI) { /** * Before adding new values update old contents to blank */ try { var url = aProgress.DOMWindow.location.href; statusBar.getTagometerData(url); changeTagIcon(url); } catch(e) { //This is happening on startup at times. yDebug.print("Exception in ybookmarkStatusOverlay.js::urlBarListener::onLocationChange:" + e, YB_LOG_MESSAGE); } }, onStateChange: function() {}, onProgressChange: function() {}, onStatusChange: function() {}, onSecurityChange: function() {}, onLinkIconAvailable: function() {} }; /** * Status Bar class handles all the things on status bar */ var statusBar = { delIcon: null, alertIcon: null, networkIcon: null, inboxIcon: null, tagoIcon: null, delIconOff: null, networkOff: null, inboxActive: null, tagoActive: null, prefService: null, extBranch: null, links4u: 0, tagoCount: null, alertWindow: null, tagoWindow: null, strbundle: null, alertMessage: null, os: null, hash: null, networkTimer: null, alertTimer: null, //alertInfoPopupTimer: null, //oldAlertTimerInterval: null, alertUpdatetime: null, alertLastUpdateTime: null, tagReq: null, prefsUpdateTimer: null, tagoRequestFailCount: 0, canShowAlertWindow: true, init: function () { this.delIcon = new statusBarIcon("delicious-status-bar-delicious-image"); this.alertIcon = new statusBarIcon("delicious-status-bar-alert-image"); this.networkIcon = document.getElementById("delicious-status-bar-network-image"); this.inboxIcon = new statusBarIcon("delicious-status-bar-inbox-image", "delicious-status-bar-inbox-count"); this.inboxIcon.hideIcon(); this.tagoIcon = new statusBarIcon("delicious-status-bar-vitality-image", "delicious-status-bar-vitality-count"); this.alertWindow = new popWindow('delicious-status-bar-popup'); this.tagoWindow = new popWindow("tagometer-popup"); this.strbundle = document.getElementById("ybookmarks-status-bar-strings"); try { this.register(); } catch(e) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::init()=>Exception: "+e,YB_LOG_MESSAGE); } }, register: function () { try { this.prefService = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService); this.extBranch = this.prefService.getBranch("extensions.ybookmarks@yahoo"); this.extBranch.QueryInterface(Components.interfaces.nsIPrefBranch2); this.extBranch.addObserver("", this, false); this.os = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); this.os.addObserver ( this, "ybookmark.updateLinks4u", false ); this.os.addObserver ( this, "ybookmark.userChanged", false ); //Listen for webpage loads gBrowser.addProgressListener(urlBarListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT); } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::register()=>Exception: "+e,YB_LOG_MESSAGE); } }, unregister: function () { if(this.extBranch) { try { this.extBranch.removeObserver("", this); } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::unregister()=>Exception: "+e,YB_LOG_MESSAGE); } } if(this.os) { try { this.os.removeObserver(this, "ybookmark.updateLinks4u"); this.os.removeObserver(this, "ybookmark.userChanged"); } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::unregister()=>Exception: "+e,YB_LOG_MESSAGE); } } //remove progress listner gBrowser.removeProgressListener(urlBarListener); }, getUpdatedPrefs: function () { try { this.networkOff = this.prefService.getBoolPref("extensions.ybookmarks@yahoo.statusbaricons.disable_networkreminder"); this.inboxActive = this.prefService.getBoolPref("extensions.ybookmarks@yahoo.statusbaricons.include_linksforyou"); //this.tagoActive = this.prefService.getBoolPref("extensions.ybookmarks@yahoo.statusbaricons.include_tagometer"); this.delIconOff = this.prefService.getBoolPref("extensions.ybookmarks@yahoo.statusbaricons.disable_delicious_icon"); this.tagoActive = false; this.updateTagoCount(); this.setTagometerMessage(""); if(this.networkOff && !this.inboxActive && this.delIconOff) { document.getElementById("delicious-status-bar-panel").hidden = true; } else { document.getElementById("delicious-status-bar-panel").hidden = false; } } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::getUpdatedPrefs()=>Exception: "+e,YB_LOG_MESSAGE); } }, loadIcons: function () { try { this.delIcon.setImage("chrome://ybookmarks/skin/deliciousIconSmall.gif"); if(this.delIconOff) { this.delIcon.hideIcon(); } else { this.delIcon.showIcon(); } this.alertIcon.setImage("chrome://ybookmarks/skin/alertTransparent.gif"); //hide the alert icon initially //this.alertIcon.hideIcon(); this.inboxIcon.setImage((this.links4u > 0) ? "chrome://ybookmarks/skin/inboxActive.gif" : "chrome://ybookmarks/skin/inboxInactive.gif"); this.tagoIcon.setImage(this.tagoActive?"chrome://ybookmarks/skin/tagometerActive.gif":"chrome://ybookmarks/skin/tagometerInactive.gif"); if(this.inboxActive) { this.inboxIcon.showIcon(); if(this.links4u > 0) this.inboxIcon.showLabel(); this.inboxIcon._iconLabel.setAttribute("tooltiptext", this.strbundle.getFormattedString("extensions.ybookmarks.statusbar.links4uIcon.tooltip", [ this.links4u ])); this.inboxIcon._icon.setAttribute("tooltiptext", this.strbundle.getFormattedString("extensions.ybookmarks.statusbar.links4uIcon.tooltip", [ this.links4u ])); this.inboxIcon._icon.setAttribute("onclick", "ybookmarksUtils.openLinkToNewTab('"+deliciousService.getLinks4uUrl()+"'); statusBar.updateLinks4u();"); this.inboxIcon._iconLabel.setAttribute("onclick", "ybookmarksUtils.openLinkToNewTab('"+deliciousService.getLinks4uUrl()+"'); statusBar.updateLinks4u();"); } else { this.inboxIcon.hideIcon(); this.inboxIcon.hideLabel(); this.inboxIcon._iconLabel.removeAttribute("tooltiptext"); this.inboxIcon._icon.removeAttribute("tooltiptext"); } if(this.tagoActive && this.tagoCount > 0) { this.tagoIcon.showLabel(); this.tagoIcon._iconLabel.setAttribute("tooltiptext", this.strbundle.getFormattedString("extensions.ybookmarks.statusbar.tagometerIcon.tooltip", [ this.tagoCount ])); this.tagoIcon._icon.setAttribute("tooltiptext", this.strbundle.getFormattedString("extensions.ybookmarks.statusbar.tagometerIcon.tooltip", [ this.tagoCount ])); } else { this.tagoIcon._iconLabel.removeAttribute("tooltiptext"); this.tagoIcon._icon.removeAttribute("tooltiptext"); this.tagoIcon.hideLabel(); } } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::loadIcons()=>Exception: "+e,YB_LOG_MESSAGE); } }, reloadNetwork: function () { if(statusBar.networkOff) { statusBar.networkIcon.hidden = true; statusBar.clearNetworkTimer(); } else { statusBar.networkIcon.hidden = false; statusBar.setNetworkTimer(); } }, observe: function (aSubject, aTopic, aData) { switch(aTopic) { case "nsPref:changed": try { this.getUpdatedPrefs(); this.loadIcons(); this.reloadNetwork(); if(this.tagoActive) { statusBar.getTagometerData(gBrowser.contentWindow.location.href); } } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::observe()=>Exception: "+e,YB_LOG_MESSAGE); } break; case "ybookmark.updateLinks4u": this.updateLinks4u(aData); break; case "ybookmark.userChanged": if(aData == "loggedin") { statusBar.setNetworkTimer(); //statusBar.setAlertTimer(); } else if(aData == "loggedout" || aData == "cookie_expired" || aData == "silentlogout") { statusBar.clearNetworkTimer(); //statusBar.clearAlertTimer(); } break; } }, updateLinks4u: function (links) { if(!this.inboxActive) { this.inboxIcon.hideLabel(); return; } this.links4u = (!links)?0:links; if(this.links4u <= 0) { this.inboxIcon.hideLabel(); } else { this.inboxIcon.setLabel(this.links4u); this.inboxIcon.showLabel(); } this.loadIcons(); }, updateTagoCount: function (count) { if(!this.tagoActive) { this.tagoIcon.hideLabel(); this.tagoIcon.hideIcon(); return; } this.tagoCount = (!count) ? 0 : count; if(this.tagoCount > 0) { var title = document.getElementById("tagometer-popuptitle-label"); if(this.tagoCount == 1) { title.value = this.strbundle.getString("extensions.ybookmarks.statusbar.tagometer.single.title"); } else { title.value = this.strbundle.getString("extensions.ybookmarks.statusbar.tagometer.multi.title"); } this.tagoIcon.setLabel(this.tagoCount); this.tagoIcon.showLabel(); this.tagoIcon.showIcon(); } else { this.tagoIcon.hideIcon(); this.tagoIcon.hideLabel(); } this.loadIcons(); }, getTagometerData: function(url) { // Do nothing if tagometer is disabled if(!this.tagoActive) { return; } if(this.tagReq) { this.tagReq.abortRequest(); } this.updateTagoCount(); this.setTagometerMessage(""); if(url != "about:blank") { var msg = ""; var hash = hex_md5(url); this.hash = hash; // this.hash = encodeURIComponent(url); yDebug.print("ybookmarkStatusOverlay.js::statusBar::getTagometerData()=> hash: "+this.hash,YB_LOG_MESSAGE); yDebug.print("ybookmarkStatusOverlay.js::statusBar::getTagometerData()=> calling: "+deliciousService.getTagometerUrl()+this.hash,YB_LOG_MESSAGE); var callBack = { onload : function(event) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::getTagometerData()=> Called Callback. Response"+event.target.responseText,YB_LOG_MESSAGE); if(event.target.responseText) { var response = eval(event.target.responseText); if(typeof(response) == "object") { statusBar.updateTagoCount(response[0]["total_posts"]); statusBar.setTagometerMessage(response[0]["top_tags"]); //reset failed requests counter statusBar.tagoRequestFailCount = 0; } } }, onprogress: function(event) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::getTagometerData()=> status: "+event.target.status,YB_LOG_MESSAGE); }, onerror : function(event) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::getTagometerData()=> Error: Error in fetching tagometer data. Resending the request.",YB_LOG_MESSAGE); //resend only if less than 2 requests have already sent if(statusBar.tagoRequestFailCount < 2) { //resend the fetch request if error occurs statusBar.getTagometerData(gBrowser.contentWindow.location.href); statusBar.tagoRequestFailCount++; } } }; this.tagReq = new yHttpGet(deliciousService.getTagometerUrl()+this.hash, callBack); } }, showAlertWindow: function (objRef) { try { /* if(statusBar.alertLink) { document.getElementById("delicious-status-bar-popupbottom").style.display = ''; document.getElementById("delicious-status-bar-goto-link").setAttribute("onclick", "ybookmarksUtils.openLinkToNewTab('"+statusBar.alertLink+"'); statusBar.hideAlertWindow();"); document.getElementById("delicious-status-bar-goto-image").setAttribute("onclick", "ybookmarksUtils.openLinkToNewTab('"+statusBar.alertLink+"'); statusBar.hideAlertWindow();"); } else { document.getElementById("delicious-status-bar-popupbottom").style.display = 'none'; } */ /** * Show alert window only if browser window is focused */ if(!statusBar.canShowAlertWindow) return; //this.alertWindow.prepareContent("delicious-status-bar-popupcontent-label", this.alertMessage); document.getElementById("delicious-status-bar-popupcontent-label").innerHTML = this.alertMessage; statusBar.alertWindow.preparePosition('bottomright'); this.alertWindow.show(objRef); } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::showAlertWindow()=>Exception: "+e,YB_LOG_MESSAGE); } }, hideAlertWindow: function () { this.alertWindow.hide(); //this.alertIcon.hideIcon(); }, showTagoWindow: function (objRef) { if(this.tagoCount) { try { this.tagoWindow.perpareElement("tagometer-popuptitle-count", "value", this.tagoCount); this.tagoWindow.perpareElement("tagometer-goto-link", "onclick", "ybookmarksUtils.openLinkToNewTab('"+deliciousService.getUrl("url/"+this.hash)+"'); statusBar.hideTagoWindow();"); this.tagoWindow.perpareElement("tagometer-goto-image", "onclick", "ybookmarksUtils.openLinkToNewTab('"+deliciousService.getUrl("url/"+this.hash)+"'); statusBar.hideTagoWindow();"); this.tagoWindow.prepareContent("tagometer-popupcontent-label", this.tagometerMessage); this.tagoWindow.posX = -1; this.tagoWindow.posY = -1; this.tagoWindow.show(objRef); } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::showTagoWindow()=>Exception: "+e,YB_LOG_MESSAGE); } } }, hideTagoWindow: function () { this.tagoWindow.hide(); }, setAlertMessage: function (msg) { this.alertMessage = msg; }, setTagometerMessage: function (topTags) { if(typeof(topTags) == "object") { var i = 1; /** * If toptags are blank dont show popup window */ if(topTags == "") { this.tagoWindow.disable(); } else { this.tagoWindow.enable(); } for(var c in topTags) { if(i > 5) break; //skip tag imported if(c == "imported") { i++; continue; } document.getElementById("tagometer-toptag"+i).value = c; document.getElementById("tagometer-toptag"+i).style.display = ""; document.getElementById("tagometer-toptag"+i).setAttribute("onclick","ybookmarksUtils.openLinkToNewTab(deliciousService.getUrl('"+"popular/"+c+"')); statusBar.hideTagoWindow();"); i++; document.getElementById("tagometer-toptags-head").style.display = ""; } } else { document.getElementById("tagometer-toptags-head").style.display = "none"; for(i=0; i < 5; i++) { document.getElementById("tagometer-toptag"+(i+1)).style.display = "none"; } //set tago label empty this.tagoIcon.setLabel(""); } }, //for alpha _getTextContents : function(node) { var result = ""; var doc = node.ownerDocument; doc.QueryInterface(CI.nsIDOMDocumentTraversal); var treeWalker = doc.createTreeWalker(node, CI.nsIDOMNodeFilter.SHOW_TEXT | CI.nsIDOMNodeFilter.SHOW_CDATA_SECTION, null, true); var curNode = treeWalker.currentNode; while (curNode) { try { curNode.QueryInterface(CI.nsIDOMCharacterData); result += curNode.data; } catch (e) {} curNode = treeWalker.nextNode(); } return result; }, //for alpha getTimeFromDOM: function(posts) { var dateString = null; try { var rssDOM = posts.queryElementAt(0, CI.nsIDOMDocument); var nodeList = rssDOM.getElementsByTagName("item"); if(nodeList && nodeList.length) { var node = nodeList[0]; var childNode = node.firstChild; while(childNode) { if (childNode.nodeType == CI.nsIDOMNode.ELEMENT_NODE) { childNode.QueryInterface(CI.nsIDOMElement); var childName = childNode.nodeName; if (childName == "dc:date") { dateString = statusBar._getTextContents(childNode); //yDebug.print("dateString is : " + dateString, YB_LOG_MESSAGE); return dateString; } } childNode = childNode.nextSibling; } } } catch(e) { yDebug.print("exception in getTimefromDOM"); } return dateString; }, activateNetworkIcon : function() { statusBar.networkIcon.setAttribute("status", "active"); statusBar.networkIcon.setAttribute("tooltiptext", statusBar.strbundle.getString("extensions.ybookmarks.statusbar.network.active.tooltip")); }, inactivateNetworkIcon : function() { statusBar.networkIcon.setAttribute("status", "inactive"); statusBar.networkIcon.setAttribute("tooltiptext", statusBar.strbundle.getString("extensions.ybookmarks.statusbar.network.inactive.tooltip")); }, handleNetwork : function () { if(deliciousService.getUserName()) { var cb = { onload : function(posts) { if(!posts) { return; } /* //yDebug.print("valid post,length:"+ posts.length); var rssDOM = posts.queryElementAt(0, Components.interfaces.nsIDOMDocument); var timeArray = ybookmarksUtils.evaluateXPath(rssDOM,"//item[1]/pubDate"); var time = null; if(timeArray && timeArray[0]) { time = timeArray[0].textContent; } */ var time = statusBar.getTimeFromDOM(posts); //Do this only if user is logged in if(time && deliciousService.getUserName()) { var storeService = Components.classes["@mozilla.org/ybookmarks-store-service;1"]. getService(Components.interfaces.nsIYBookmarksStoreService); var lastTime = storeService.getFeedLastUpdateTime(deliciousService.getNetworkFeedUrl()); //Show the icon,There is some nw activity if(!lastTime) { statusBar.activateNetworkIcon(); } else if(time != lastTime) { statusBar.activateNetworkIcon(); } } }, onerror : function(event) { yDebug.print("ybookmarksStatusOverlay.js:handleNetwork:Onerror",YB_LOG_MESSAGE); } } var socialStore = Components.classes["@yahoo.com/socialstore/delicious;1"]. getService(Components.interfaces.nsISocialStore); socialStore.getFeedData(deliciousService.getNetworkFeedUrl(), cb); } }, onNetworkClick: function () { //Make icon inactive statusBar.inactivateNetworkIcon(); //Open the network page. ybookmarksUtils.openLinkToNewTab(deliciousService.getNetworkUrl()); var cb = { onload : function(posts) { if(!posts) { return; } /* var rssDOM = posts.queryElementAt(0, Components.interfaces.nsIDOMDocument); var timeArray = ybookmarksUtils.evaluateXPath(rssDOM,"//item[1]/pubDate"); var time = null; if(timeArray && timeArray[0]) { time = timeArray[0].textContent; } */ var time = statusBar.getTimeFromDOM(posts); if(time && deliciousService.getUserName()) { var storeService = Components.classes["@mozilla.org/ybookmarks-store-service;1"]. getService(Components.interfaces.nsIYBookmarksStoreService); storeService.setFeedLastUpdateTime(deliciousService.getNetworkFeedUrl(), time); } }, onerror : function(event) { yDebug.print("ybookmarksStatusOverlay.js:OnNetworkClick:Onerror",YB_LOG_MESSAGE); } } //Do this only if user is logged in if(deliciousService.getUserName()) { //Get the latest timestamp var socialStore = Components.classes["@yahoo.com/socialstore/delicious;1"]. getService(Components.interfaces.nsISocialStore); socialStore.getFeedData(deliciousService.getNetworkFeedUrl(), cb); } }, setNetworkTimer : function () { //User must be logged in. if(!deliciousService.getUserName()) { return; } //default to 10 minutes yDebug.print("ybookmarksStatusOverlay.js::setNetworkTimer",YB_LOG_MESSAGE); var interval = 60*10; //seconds => 10 minutes try { interval = this.prefService.getIntPref("extensions.ybookmarks@yahoo.statusbaricons.networkpoll.interval"); } catch(e) {} statusBar.clearNetworkTimer(); if (!statusBar.networkTimer) { statusBar.networkTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); } else { statusBar.networkTimer.cancel(); } statusBar.networkTimer.initWithCallback(this, interval * 1000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK); }, clearNetworkTimer : function () { if(statusBar.networkTimer) { statusBar.networkTimer.cancel(); statusBar.networkTimer = null; } }, /* setAlertInfoPopupTimer : function () { yDebug.print("ybookmarksStatusOverlay.js::setAlertInfoPopup Timer",YB_LOG_MESSAGE); var interval = 5*1000;// 5 seconds if (!statusBar.alertInfoPopupTimer) { statusBar.alertInfoPopupTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); } else { statusBar.alertInfoPopupTimer.cancel(); } statusBar.alertInfoPopupTimer.initWithCallback(this, interval, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK); }, clearAlertInfoPopupTimer : function () { if(statusBar.alertInfoPopupTimer) { statusBar.alertInfoPopupTimer.cancel(); } }, */ setAlertTimer : function (delay) { //default to 10 minutes yDebug.print("ybookmarksStatusOverlay.js::setAlertTimer",YB_LOG_MESSAGE); var interval = 60 * 10; //seconds => 10 minutes try { interval = this.prefService.getIntPref("extensions.ybookmarks@yahoo.statusbaricons.alertpoll.interval"); } catch(e) {} if (!statusBar.alertTimer) { statusBar.alertTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); } else { statusBar.alertTimer.cancel(); } /* statusBar.oldAlertTimerInterval = interval; if(delay) interval = delay; //else interval *= 60; */ yDebug.print("ybookmarksStatusOverlay.js:handleAlert:Timer set to "+interval+" secs",YB_LOG_MESSAGE); statusBar.alertTimer.initWithCallback(this, interval * 1000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK); }, clearAlertTimer : function () { if(statusBar.alertTimer) { statusBar.alertTimer.cancel(); statusBar.alertTimer = null; } }, handleAlert : function () { if(deliciousService.getUserName()) { var cb = { onload : function(posts) { if(!posts) { return; } var rssDOM = posts.queryElementAt(0, Components.interfaces.nsIDOMDocument); var timeArray = ybookmarksUtils.evaluateXPath(rssDOM,"//item[1]/pubDate"); var time = null; if(timeArray && timeArray[0]) { time = timeArray[0].textContent; } if(!time) { statusBar.alertIcon.hideIcon(); return; } else { alertUpdatetime = time; } /* if(statusBar.alertWindow.preparePosition('bottomright') == false){ //Put 10 seconds interval since popup is to be shown statusBar.clearAlertTimer(); statusBar.setAlertTimer(10); return; } */ //Do this only if use is logged in if(time && deliciousService.getUserName()) { try { var storeService = Components.classes["@mozilla.org/ybookmarks-store-service;1"]. getService(Components.interfaces.nsIYBookmarksStoreService); alertLastUpdateTime = storeService.getFeedLastUpdateTime(deliciousService.getAlertFeedUrl()); var titleArray = ybookmarksUtils.evaluateXPath(rssDOM,"//item[1]/title"); var linkArray = ybookmarksUtils.evaluateXPath(rssDOM,"//item[1]/link"); var categoryArray = ybookmarksUtils.evaluateXPath(rssDOM,"//item[1]/category"); var title = titleArray[0].textContent; var category = categoryArray[0].textContent; } catch(e) { statusBar.alertIcon.hideIcon(); return; } /** * Check if title is not empty */ if(title) { /** * Check if title contains at least one anchor tag */ if(title.search(/href=/i) > -1) { /** * Parse title for anchors and add styles to them and add functionality to them */ title = ybookmarksUtils.parseTextForAnchors(title); // alert(title); } statusBar.setAlertMessage(title); //statusBar.setAlertMessage(title+'and <a href="http://www.yahoo.com" onclick="ybookmarksUtils.openLinkToNewTab('+"'http://www.yahoo.com/'"+')">Yahoo!</a>'); } else { statusBar.alertIcon.hideIcon(); return; } if(time && alertLastUpdateTime && time==alertLastUpdateTime) { statusBar.alertIcon.showIcon(); } else if(!alertLastUpdateTime || time!=alertLastUpdateTime){ statusBar.alertIcon.showIcon(); if (category == "warn"){ if (ybookmarksUtils.getTopWindow() == window) { statusBar.showAlertWindow(document.getElementById("delicious-status-bar-alert-image")); } //Put old interval since popup is already shown if interval is 10 seconds /* if(statusBar.alertTimer.delay == 10000){ statusBar.alertTimer.initWithCallback(this, statusBar.oldAlertTimerInterval, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK); }*/ } else if (category == "info"){ if (ybookmarksUtils.getTopWindow() == window) { statusBar.showAlertWindow(document.getElementById("delicious-status-bar-alert-image")); window.setTimeout(function() {statusBar.hideAlertWindow();}, 5000); } //yDebug.print("ybookmarksStatusOverlay.js:handleAlert: delay "+statusBar.alertTimer.delay,YB_LOG_MESSAGE); //Put old interval since popup is already shown if interval is 10 seconds /* if(statusBar.alertTimer.delay == 10000){ statusBar.clearAlertTimer(); statusBar.setAlertTimer(statusBar.oldAlertTimerInterval); }*/ //start a timer that will close the alert window in 5 seconds //statusBar.setAlertInfoPopupTimer(); } //storeService.setFeedLastUpdateTime(deliciousService.getAlertFeedUrl(), time); } } }, onerror : function(event) { yDebug.print("ybookmarksStatusOverlay.js:handleAlert:Onerror",YB_LOG_MESSAGE); } } var socialStore = Components.classes["@yahoo.com/socialstore/delicious;1"]. getService(Components.interfaces.nsISocialStore); socialStore.getFeedData(deliciousService.getAlertFeedUrl(), cb); } }, alertPopupPresented : function() { if(alertUpdatetime != alertLastUpdateTime) { var storeService = Components.classes["@mozilla.org/ybookmarks-store-service;1"]. getService(Components.interfaces.nsIYBookmarksStoreService); storeService.setFeedLastUpdateTime(deliciousService.getAlertFeedUrl(), alertUpdatetime); } }, canShowAlert: function () { statusBar.canShowAlertWindow = true; }, cantShowAlert: function () { statusBar.canShowAlertWindow = false; }, notify : function (aTimer) { if (aTimer == statusBar.networkTimer){ yDebug.print("ybookmarksStatusOverlay.js:notify=> Network Timer notified.",YB_LOG_MESSAGE); statusBar.handleNetwork(); }else if (aTimer == statusBar.alertTimer){ yDebug.print("ybookmarksStatusOverlay.js:notify=> Alert Timer notified.",YB_LOG_MESSAGE); statusBar.handleAlert(); }else if (aTimer == statusBar.prefsUpdateTimer) { statusBar.getTagometerData(gBrowser.contentWindow.location.href); } }, loadStatusBar : function () { //:::Classic or FullMode::: if(ybookmarksUtils.getExtensionMode() == YB_EXTENSION_MODE_CLASSIC) { //Toolbar removal var element = document.getElementById("navigator-toolbox"); if(element.hasChildNodes()){ for (var i = 0; i < element.childNodes.length; i++) { if(element.childNodes[i].id == "ybToolbar") { element.removeChild(element.childNodes[i]); break; } } } //Hide sidebar button for classic mode. var sidebarButton = document.getElementById("del-button-delicious"); if(sidebarButton) { sidebarButton.hidden = true; } /* var sidebar = document.getElementById("sidebar-box"); // close sidebar. if (!sidebar.hidden) { toggleSidebar('viewYBookmarksSidebar', false); } */ return false; } else { var showList = [ "delicious-status-bar-panel", //show status bar //"del-button-delicious", //show sidebar button "yb-viewSidebarMenuItem" //show sidebar menu ]; function showElem(element) { var elem = document.getElementById(element); if(elem) { elem.hidden = false; } } showList.forEach(showElem); } try { yDebug.print("ybookmarkStatusOverlay.js::loadStatusBar()=>Invoked ",YB_LOG_MESSAGE); statusBar.init(); yDebug.print("ybookmarkStatusOverlay.js::loadStatusBar()::statusBar.init()=>Initialized ",YB_LOG_MESSAGE); statusBar.getUpdatedPrefs(); yDebug.print("ybookmarkStatusOverlay.js::loadStatusBar()::statusBar.getUpdatedPrefs()=>Updated Pref Fetched ",YB_LOG_MESSAGE); statusBar.loadIcons(); statusBar.reloadNetwork(); //no alert in alpha statusBar.alertIcon.hideIcon(); yDebug.print("ybookmarkStatusOverlay.js::loadStatusBar()::statusBar.loadIcons()=>Icons Loaded ",YB_LOG_MESSAGE); /* No alert in alpha statusBar.setAlertTimer(); window.addEventListener("focus", statusBar.canShowAlert, true); window.addEventListener("blur", statusBar.cantShowAlert, true); */ } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::loadStatusBar()=>Exception: "+e,YB_LOG_MESSAGE); } }, statusBarCleanup : function () { try { statusBar.unregister(); statusBar.clearNetworkTimer(); statusBar.clearAlertTimer(); window.removeEventListener("focus", statusBar.canShowAlert, true); window.removeEventListener("blur", statusBar.cantShowAlert, true); } catch (e) { yDebug.print("ybookmarkStatusOverlay.js::statusBar::cleanup()=>Exception: "+e,YB_LOG_MESSAGE); } } }; function deleteStatusbarHeap() { statusBar.statusBarCleanup(); statusBar = null; } //statusBar. window.addEventListener("load", statusBar.loadStatusBar, false); window.addEventListener("unload", deleteStatusbarHeap, false);